#ifndef MOONLIGHT_OHOS_MOUSECONTROLLER_H
#define MOONLIGHT_OHOS_MOUSECONTROLLER_H

#include <ace/xcomponent/native_interface_xcomponent.h>
#include <atomic>
#include <thread>

class MouseController {
protected:
    using MouseEvent = OH_NativeXComponent_MouseEvent;

public:
    MouseController();
    virtual ~MouseController();

    virtual void handle(OH_NativeXComponent *const xcomp, void *const win, const MouseEvent &event);

private:
    std::atomic<bool> updated = false;
    std::atomic<float> x = -1, y = -1, refWidth = -1, refHeight = -1;
    std::thread loop;
    std::atomic<bool> stopFlag = false;
    std::condition_variable stopCond;

    void updateCurrentPosition(float x, float y, float refWidth, float refHeight);
};

#endif //MOONLIGHT_OHOS_MOUSECONTROLLER_H
